#include "clock.h"
#include "city.h"

//////////////////////////////////////////////////
// Clock::Clock(City* city)
//////////////////////////////////////////////////
Clock::Clock(City* city)
{
    this->city = city;
}

//////////////////////////////////////////////////
//  void Clock::update(double dt)
//////////////////////////////////////////////////
void Clock::update(double dt)
{
    if (framesSinceLastTick >= framesPerTick)
    {
        city->tick();
        framesSinceLastTick = 0;
    }

    framesSinceLastTick++;
    numTicks++;
}

//////////////////////////////////////////////////
//  void Clock::setSpeed(City::SimSpeed speed)
//////////////////////////////////////////////////
void Clock::setSpeed(Clock::SimSpeed speed)
{
    this->speed = speed;
    framesPerTick = 50/(int)this->speed;
}

//////////////////////////////////////////////////
//  void Clock::increaseSpeed()
//////////////////////////////////////////////////
void Clock::increaseSpeed()
{
    int iSpeed = (int)speed;
    iSpeed++;

    if (iSpeed > (int)Clock::SPEED_FASTER)
    {
        iSpeed = (int)Clock::SPEED_FASTER;
    }

    setSpeed((Clock::SimSpeed)iSpeed);
}

//////////////////////////////////////////////////
//  void Clock::decreaseSpeed()
//////////////////////////////////////////////////
void Clock::decreaseSpeed()
{
    int iSpeed = (int)speed;
    iSpeed--;

    if (iSpeed < (int)Clock::SPEED_SLOWER)
    {
        iSpeed = (int)Clock::SPEED_SLOWER;
    }

    setSpeed((Clock::SimSpeed)iSpeed);
}
